<script setup lang='ts'>
  import { onMounted, reactive, ref } from 'vue';
  import { guild_roomApi } from '@/api/controller';
  import { ToastSuccess, Toastloading } from '@/utils/public';
  import Pagination from "@/components/Pagination/index.vue";
  import { ElMessageBox } from 'element-plus';
  import closeForm from './closeForm.vue';
  const closeFormRef = ref()
  const action = reactive({
    total:0,
    list:[] as any[],
  })
  const listQuery = reactive({
    page: 1,
    limit: 20,
  })
  const handleCloseForm = (row:any = {})=>{
    closeFormRef.value.openDialog(row)
  }
  const handleDelete = (row:any = {})=>{
    ElMessageBox.confirm("确定删除此关闭记录吗?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    })
    .then(async () => {
      const loading = Toastloading();
      await guild_roomApi.delCloseRoomLog({
        id:row.id
      });
      loading.close();
      ToastSuccess("删除成功!");
      getList();
    })
    .catch(() => {});
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    action.list = []
    action.total = 0
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const res = await guild_roomApi.getRoomCloseLog(listQuery)
    loading.close()
    const { data=[], total=0 } = res.data
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">刷新</el-button>
          <el-button type="primary" @click="handleCloseForm()">关闭房间</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-main xm-TableCenter"
      :data="action.list"
      border
    >
    <el-table-column width="100" prop="room_uid" label="房间UID" />
    <el-table-column width="140" prop="admin_name" label="操作人" />
    <el-table-column min-width="100" show-overflow-tooltip prop="desc" label="关闭理由" />
    <el-table-column width="220" prop="created_at" label="操作时间" />
      <el-table-column width="220" fixed="right" label="操作">
        <template #default="scoped">
          <el-button type="primary" @click="handleCloseForm(scoped.row)">编辑</el-button>
          <el-button type="danger" @click="handleDelete(scoped.row)" >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <closeForm ref="closeFormRef" @update-list="getList" />
  </div>
</template>